package com.example.spsave;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class LoginActivity extends AppCompatActivity {

    private EditText et_account , et_password;
    private Button btn_login , checkbox;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_login);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        checkbox = findViewById(R.id.checkBox);
        btn_login = findViewById(R.id.btn_login);
        TextView tv_zc = findViewById(R.id.tv_zc);
        et_account = findViewById(R.id.et_account);
        et_password = findViewById(R.id.et_password);

        SharedPreferences sp1 = getSharedPreferences("AccountAndPassword",MODE_PRIVATE);
        et_account.setText(sp1.getString("account",""));
        et_password.setText(sp1.getString("password",""));



        checkbox.setOnClickListener(v ->
        {
           SharedPreferences sp =  getSharedPreferences("AccountAndPassword",MODE_PRIVATE);
           SharedPreferences.Editor editor = sp.edit();
           editor.putString("account",et_account.getText().toString().trim());
            editor.putString("password",et_password.getText().toString().trim());

           editor.commit();
        });

    }
}